<?php
namespace Home\Controller;
use Think\Controller;

/**
 * 球会控制
 */
class ClubController extends Controller{
	//全局变量区
	/**
	 * 布局相关
	 * list_each_page_number：每一页列表条数
	 */
	public $list_each_page_number = 5;
	/**
	 * 俱乐部成员相关变量
	 * club_member_status成员状态：
	 *     club_member_status_1：正式会员
	 *     club_member_status_2：申请中
	 */
	public $club_member_status_1 = 1;
	public $club_member_status_2 = 2;

	//**********进入球会详情前教练列表部分**********//

	/**
	 * 进入球会主页面
	 */
	public function index(){
		$this->display();
	}

	/**
	 * 列表全部球会
	 */
	public function listAllClub(){
		//实例化球会信息视图对象
		$clubInfo = M('club_info_view');

		//位置信息
		$e_page_num = $this->list_each_page_number;  //每一页的球馆条数
		$page_num = $_POST['page_num'];;  //页数

		//置位
		$start_p = $e_page_num * ($page_num - 1);

		//查询
		
		$result = $clubInfo->limit($start_p, $e_page_num)->select();
		$resultCount = $clubInfo->count();

		//ajax返回
		$resultList['result'] = $result;
		$resultList['page_num'] = $page_num;
		$resultList['result_count'] = $resultCount;
		$this->ajaxReturn($resultList);
	}

	/**
	 * 列表当前区域下球会
	 */
	public function listAreaClub(){
		//从前端获取地理位置信息
		$club_location['club_province'] = $_POST['club_province'];
		$club_location['club_city'] = $_POST['club_city'];
		$club_location['club_district'] = $_POST['club_district'];

		//实例化球会信息视图对象
		$clubInfo = M('club_info_view');

		//位置信息
		$e_page_num = $this->list_each_page_number;  //每一页的球馆条数
		$page_num = $_POST['page_num'];;  //页数

		//置位
		$start_p = $e_page_num * ($page_num - 1);

		//查询
		$result = $clubInfo->where($club_location)->limit($start_p, $e_page_num)->select();
		$resultCount = $clubInfo->where($club_location)->count();

		//ajax返回
		$resultList['result'] = $result;
		$resultList['page_num'] = $page_num;
		$resultList['result_count'] = $resultCount;
		$this->ajaxReturn($resultList);
	}

	/**
	 * 搜索球会
	 */
	public function searchClub(){
		//从前端获取模糊信息
		$clubName = $_POST['name'];

		//实例化球会信息视图对象
		$clubInfo = M('club_info_view');

		//位置信息
		$e_page_num = $this->list_each_page_number;  //每一页的球馆条数
		$page_num = $_POST['page_num'];;  //页数

		//置位
		$start_p = $e_page_num * ($page_num - 1);

		//查询
		$name = "%".$clubName;
		$where['name'] = array('like', $name."%");
		$result = $clubInfo->where($where)->limit($start_p, $e_page_num)->select();
		$resultCount = $clubInfo->where($where)->count();

		//ajax返回
		$resultList['result'] = $result;
		$resultList['page_num'] = $page_num;
		$resultList['result_count'] = $resultCount;
		$this->ajaxReturn($resultList);
	}

	//**********进入球会详情后展示部分**********//

	/**
	 * 球会详情页面
	 */
	public function clubInfo(){
		//从前端接收球会id
		$clubId = $_GET['club_id'];
		
		//实例化球会对象
		$club = M('club_table');
		//实例化用户对象
		$user = M('user_table');
		//实例化俱乐部成员对象
		$memberList = M('club_member_table');

		//查询球会信息
		$where['id'] = $clubId;
		$clubResult = $club->where($where)->find();
		unset($where);
		$where['id'] = $clubResult['master_id'];
		$userResult = $user->where($where)->field('name, gender, email, phone')->find();
		//查询是否已在球会中
		unset($where);
		$where['member_id'] = session('id');
		$isIn = $memberList->where($where)->find();

		if($isIn){
			$this->assign('member_status', $isIn['member_status']);
		}else{
			$this->assign('member_status', 0);
		}
		//dump($clubResult);
		//return;
		$this->assign('club_info', json_encode($clubResult));
		$this->assign('master_info', json_encode($userResult));
		$this->display();
	}

	/**
	 * 加入球会
	 * 返回值：
	 *     if_applied：
	 *         1：已经申请过 0：还未申请过
	 *     apply_kind：
	 *         0：:松散型球会申请 1：紧凑型球会申请
	 *     apply_result:
	 *         0：申请失败 否则：申请成功 
	 */
	public function joinClub(){
		//从前端接收球会id
		$clubId = $_POST['club_id'];
		//实例化俱乐部成员对象
		$memberList = M('club_member_table');
		//实例化球会对象
		$club = M('club_table');

		$resultList = array();

		//判断球会类型
		$where['id'] = $clubId;
		$clubKind = $club->where($where)->field('club_kind')->find();

		//判断是否已经申请过
		unset($where);
		$where['club_id'] = $clubId;
		$where['member_id'] = session('id');
		$searchResult = $memberList->where($where)->find();
		if($searchResult){
			$resultList['if_applied'] = 1;
		}else{
			$resultList['if_applied'] = 0;
			$clubKind=implode('',$clubKind);

			//申请
			if($clubKind == 0){
				$clubMember['club_id'] = $clubId;
				$clubMember['member_id'] = session('id');
				$clubMember['join_time'] = date("y-m-d H:i:s");
				$clubMember['member_type'] = 1;
				$clubMember['member_status'] = 1;

				$addResult = $memberList->add($clubMember);
				$resultList['applyKind'] = 0;
				$resultList['addResult'] = $addResult;
			}elseif($clubKind == 1){
				$clubMember['club_id'] = $clubId;
				$clubMember['member_id'] = session('id');
				$clubMember['join_time'] = date("y-m-d H:i:s");
				$clubMember['member_type'] = 1;
				$clubMember['member_status'] = 2;

				$addResult = $memberList->add($clubMember);
				$resultList['applyKind'] = 1;
				$resultList['addResult'] = $addResult;
				$this->ajaxReturn($resultList);
			}
		}

		$this->ajaxReturn($resultList);
	}

	//**********球会主页相关**********//

	/**
	 * 列表球会成员
	 */
	public function listClubMember(){
		//从前端获取clubid
		$clubId = $_POST['club_id'];

		//实例化club成员对象
		$clubMember = M('club_member_table');

		//位置信息
		$e_page_num = $this->list_each_page_number;  //每一页的球馆条数
		$page_num = $_POST['page_num'];  //页数

		//置位
		$start_p = $e_page_num * ($page_num - 1);

		//获取成员list
		$where['club_id'] = $clubId;
		$where['member_status'] = $this->club_member_status_1;
		$result = $clubMember->where($where)->limit($start_p, $e_page_num)->select();
		$resultCount = $clubMember->where($where)->count();

		//ajax返回
		$resultList['result'] = $result;
		$resultList['page_num'] = $page_num;
		$resultList['result_ount'] = $resultCount;
		$this->ajaxReturn($resultList);
	}

	/**
	 * 列表球会公告
	 */
	public function listClubAnnouncement(){
		//从前端获取球会id
		$clubId = $_POST['club_id'];

		//前端传输数据，明确分页情况
		$e_page_num = $this->list_each_page_number;  //每一页的条数
		$page_num = $_POST['page_num'];  //页数

		//实例化公告对象
		$announcements = M('announcement_table');
		//实例化公告球馆对照对象
		$announce_club = M('announcement_club_table');

		//置位
		$start_p = $e_page_num * ($page_num - 1);

		//进行查询，列出所有该球会公告id
		$where['c_club_id'] = $clubId;
		$announceIdResult = $announce_club->where($where)->field('c_announce_id')->limit($start_p, $e_page_num)->select();
		$resultCount = $announce_club->where($where)->count();

		//获取所有公告信息组装进result
		$result = array();
		for($x1 = 0; $x1 < count($announceIdResult); $x1++){
			$announceId = $announceIdResult[$x1];
			unset($where);
			$where['announce_id'] = $announceId;
			$announceInfo = $announcements->where($where)->find();
			$result[$x1] = $announceInfo;
		}

		//ajax返回
		$resultList['result'] = $result;
		$resultList['page_num'] = $page_num;
		$resultList['result_ount'] = $resultCount;
		$this->ajaxReturn($resultList);
	}

	/**
	 * 列表球会活动
	 */
	public function listClubActivity(){
		//从前端获取球会id
		$clubId = $_POST['club_id'];

		//实例化活动球会对照对象
		$activityClub = M('activity_club_table');
		//实例化活动对象
		$activity = M('activity_table');

		//位置信息
		$e_page_num = $this->list_each_page_number;  //每一页的教练条数
		$page_num = $_POST['page_num'];;  //页数

		//置位
		$start_p = $e_page_num * ($page_num - 1);

		//进行查询，列出所有该球会活动id
		$where['club_id'] = $clubId;
		$activityIdResult = $activityClub->where($where)->field('activity_id')->limit($start_p, $e_page_num)->select();
		$resultCount = $activityClub->where($where)->count();

		//获取所有活动信息组装进result
		$result = array();
		for($x1 = 0; $x1 < count($activityIdResult); $x1++){
			$activityId = $activityIdResult[$x1];
			unset($where);
			$where['activity_id'] = $activityId;
			$activityInfo = $activity->where($where)->find();
			$result[$x1] = $activityInfo;
		}

		//ajax返回
		$resultList['result'] = $result;
		$resultList['page_num'] = $page_num;
		$resultList['result_ount'] = $resultCount;
		$this->ajaxReturn($resultList);
	}

	/**
	 * 列表球会比赛
	 */
	public function listClubCompetition(){
		//从前端获取球会id
		$clubId = $_POST['club_id'];

		//实例化比赛球会对照对象
		$competitionClub = M('competition_club_table');
		//实例化比赛对象
		$competition = M('competition_table');

		//位置信息
		$e_page_num = $this->list_each_page_number;  //每一页的教练条数
		$page_num = $_POST['page_num'];;  //页数

		//置位
		$start_p = $e_page_num * ($page_num - 1);

		//进行查询，列出所有该球会比赛id
		$where['club_id'] = $clubId;
		$competitionIdResult = $competitionClub->where($where)->field('competition_id')->limit($start_p, $e_page_num)->select();
		$resultCount = $competitionClub->where($where)->count();

		//获取所有比赛信息组装进result
		$result = array();
		for($x1 = 0; $x1 < count($competitionIdResult); $x1++){
			$competitionId = $competitionIdResult[$x1];
			unset($where);
			$where['competition_id'] = $competitionId;
			$competitionInfo = $competition->where($where)->field('competition_id, competition_name, competition_picture, competition_status')->find();
			$result[$x1] = $competitionInfo;
		}

		//ajax返回
		$resultList['result'] = $result;
		$resultList['page_num'] = $page_num;
		$resultList['result_count'] = $resultCount;
		$this->ajaxReturn($resultList);
	}

	//**********创建球会部分**********//

	/**
	 * 加载创建球会页
	 */
	public function createClub(){
		//加载当前用户信息
        $user=$_SESSION['think_'];
        $this->assign('user',$user);
        //设置当前的选项位置（即该选项为橙色)   
        $this->assign("biz_item_num",6);
    	$this->display();
	}

	/**
	 * 创建球会
	 * 返回值：
	 *     字段自动检测错误：相应错误信息
	 *     添加失败：返回3
	 *     添加成功：返回0
	 *     图片上传失败：返回对应错误信息
	 */
	public function createClubHandel(){
		//实例化球会对象
		$club = D('ClubTable');
		//实例化用户对象
		$user = M('user_table');
		
        $clubArea = M('club_area_table');
		// 自动验证 创建数据集
        if (!$data = $club->create()) {
            // 防止输出中文乱码
            header("Content-type: text/html; charset=utf-8");
            $this->error($club->getError());
            //$resultList['result'] = $club->getError();
        }else{
        	//自动验证完成，接收上传图片
        	//实例化上传类
          	$upload = new \Org\Net\UploadFile();
          	$upload->maxSize = 3145728;
          	//设置文件上传类型  
          	$upload->allowExts = array('jpg','gif','png','jpeg');  
          	//设置文件上传位置  
          	//$upload->savePath = __PUBLIC__."/Img/Uploads/";
          	$upload->savePath = "./Public/Img/Uploads/clubImg/";  
          	//设置文件上传名(按照时间)  
          	$upload->saveRule = "time";
          	if (!$upload->upload()){  
              	$this->error($upload->getErrorMsg());  
          	}else{  
              	//上传成功，获取上传信息  
              	$info = $upload->getUploadFileInfo();
              	$savename = $info[0]['savename'];
          	  	$imgurl = "__PUBLIC__/Img/Uploads/clubImg/".$savename;
          	  	$data['club_picture'] = $imgurl;
          	  	$data['master_id'] = session('id');
          	  	$data['regist_time'] = date("y-m-d H:i:s");
          	  	//$data可以不定义？
          	  	$data['club_status'] = 1;
          	  	$data['master_id']=$_SESSION['think_']['id'];

          	  	//添加球馆
				if (!($_POST['province'] && $_POST['city'] && $_POST['district']))
				{
				  $this->error("俱乐部省市区不能为空");	
				}	
        		$result = $club->add($data);
        		if(!$result){
        			//$resultList['result'] = 3;
        			$this->error('添加失败！');
        		}else{
        			//处理用户的access类型
        			$accessTypeOld = session('access');
        			$where['id'] = session('id');
        			if($accessTypeOld == 0){
        				session('access', 2);
        				$changeData['access'] = 2;
        				$user->where($where)->save($changeData);
        			}elseif($accessTypeOld == 1){
        				session('access', 4);
        				$changeData['access'] = 4;
        				$user->where($where)->save($changeData);
        			}elseif($accessTypeOld == 3){
        				session('access', 6);
        				$changeData['access'] = 6;
        				$user->where($where)->save($changeData);
        			}elseif($accessTypeOld == 5){
        				session('access', 7);
        				$changeData['access'] = 7;
        				$user->where($where)->save($changeData);
					//添加地区
					
        			}
        			//$resultList['result'] = 0;
					$club_search = M ('club_table');
					$area['club_id']=$club_search->order('id desc')->limit(1)->getField('id');
					$area['club_province']=$_POST['province'];
					$area['club_city']=$_POST['city'];
					$area['club_district']=$_POST['district'];
					$add_suc=$clubArea->add($area);
					$member=M('club_member_table');
					$clubMember['club_id']=$club_search->order('id desc')->limit(1)->getField('id');
					$clubMember['member_id']=session('id');
					$clubMember['join_time']=date("y-m-d H:i:s");
					$clubMember['member_type']=2;
					$clubMember['member_status']=1;
					$member->add($clubMember);
						$this->success('添加成功',U('Club/createClub'),3);
					
        			
        		}
          	}	
        }

        //$this->ajaxReturn($resultList);
	}

	//**********球会后台管理控制器**********//

	/**
	 * 列表我的球会
	 */
	public function listMyClub(){

        //加载当前用户信息
        $user=$_SESSION['think_'];
        $this->assign('user',$user);
        //设置当前的选项位置（即该选项为橙色)
        $this->assign("biz_item_num",7);

		//实例化球会信息视图对象
		$clubInfo = M('club_table');

		//位置信息
		//$e_page_num = $this->list_each_page_number;  //每一页的球馆条数
		//$page_num = $_POST['page_num'];  //页数

		//置位
		//$start_p = $e_page_num * ($page_num - 1);

		//查询
		$where['master_id'] = session('id');
		$result = $clubInfo->join('thinkphp_club_area_table on thinkphp_club_table.id=thinkphp_club_area_table.club_id')->where($where)->select();
		//$resultCount = $clubInfo->where($where)->count();
        
		$this->data = $result;

		//$this->page_num = $page_num;
		//$this->r_count = $$resultCount;

		$this->display(); 

		//ajax返回
		//$resultList['result'] = $result;
		//$resultList['page_num'] = $page_num;
		//$resultList['result_count'] = $resultCount;
		//$this->ajaxReturn($resultList);
	}

	/**
	 * 入会申请列表
	 */
	public function applyToBeMemberList(){
		//从前端获取球会id
		$clubId = $_POST['club_id'];

		//实例化球会成员对象
		$clubMember = M('club_member_table');

		//位置信息
		$e_page_num = $this->list_each_page_number;  //每一页的球馆条数
		$page_num = $_POST['page_num'];;  //页数

		//置位
		$start_p = $e_page_num * ($page_num - 1);

		//查询申请中成员
		$where['member_status'] = 2;
		$where['club_id'] = $clubId;
		$result = $clubMember->where($where)->imit($start_p, $e_page_num)->select();
		$resultCount = $clubMember->where($where)->count();

		//ajax返回
		$resultList['result'] = $result;
		$resultList['page_num'] = $page_num;
		$resultList['result_count'] = $resultCount;
		$this->ajaxReturn($resultList);
	}

	/**
	 * 批准入会处理
	 *     返回值：
	 *         0：批准失败
	 *         1：批准成功
	 */
	public function allowJoinClubHandel(){
		//从前端获取成员id
		$memberId = $_POST['member_id'];
		//从前端获取球会id
		$clubId = $_POST['club_id'];

		//实例化球会成员对象
		$clubMember = M('club_member_table');

		//将成员状态改为正式会员
		$where['club_id'] = $clubId;
		$where['member_id'] = $memberId;
		$data['member_status'] = 1;
		$changeResult = $clubMember->where($where)->save($data);

		if(!$changeResult){
			$resultList['allow_result'] = 0;
		}else{
			$resultList['allow_result'] = 1;
		}

		$this->ajaxReturn($resultList);
	}

	/**
	 * 拒绝入会/踢出成员 处理
	 *     返回值：
	 *         0：拒绝/踢出 失败
	 *         1：拒绝/踢出 成功
	 */
	public function refuseJoinClubHandel(){
		//从前端获取成员id
		$memberId = $_POST['member_id'];
		//从前端获取球会id
		$clubId = $_POST['club_id'];

		//实例化球会成员对象
		$clubMember = M('club_member_table');

		//将成员状态改为正式会员
		$where['club_id'] = $clubId;
		$where['member_id'] = $memberId;
		$changeResult = $clubMember->where($where)->delete();

		if(!$changeResult){
			$resultList['allow_result'] = 0;
		}else{
			$resultList['allow_result'] = 1;
		}

		$this->ajaxReturn($resultList);
	}

	/**
	 * 修改球会基本信息处理
	 *     返回值：
	 *         修改成功：1
	 *         修改失败：0
	 */
	public function changeClubInfoHandel(){
		//实例化球馆对象
		$club = M('club_table');

		//从前台获取数据
		$data = $club->create();

        //进行信息修改
        $where['id'] = $data['id'];
        	$changeResult = $club->where($where)->save($data);

        if(!$changeResult){
        	$resultList['changeResult'] = 0;
        }else{
        	$resultList['changeResult'] = 1;
        }

        $this->ajaxReturn($resultList);
	}

	/**
	 * 重新上传球会图片处理
	 *     返回值：
	 *         上传成功：1
	 *         上传失败：失败信息
	 *         更新数据库失败：0
	 */
	public function reUploadPhotoHandel(){
		//实例化球会对象
		$club = M('club_table');

		//从前台获取球馆id
		$clubId = $_POST['club_id'];

		//获取原来的图片位置并实施删除
        $where['id'] = $clubId;
        $pictureLocation = $club->where($where)->field('club_picture')->find();
        if($pictureLocation){
        	unlink($pictureLocation['club_picture']);
        }

		//实例化上传类
        $upload = new \Org\Net\UploadFile();
        $upload->maxSize = 3145728;
        //设置文件上传类型  
        $upload->allowExts = array('jpg','gif','png','jpeg');  
        //设置文件上传位置  
        //$upload->savePath = __PUBLIC__."/Img/Uploads/";
        $upload->savePath = "./Public/Img/Uploads/clubImg/";  
        //设置文件上传名(按照时间)  
        $upload->saveRule = "time";
        if (!$upload->upload()){  
            $resultList['result'] = $upload->getErrorMsg();  
        }else{  
            //上传成功，获取上传信息  
            $info = $upload->getUploadFileInfo();
            $savename = $info[0]['savename'];
          	$imgurl = "__PUBLIC__/Img/Uploads/clubImg/".$savename;
          	$data['club_picture'] = $imgurl;

          	//刷新数据库
          	$refreshResult = $club->where($where)->save($data);

          	//组装返回数据
          	if(!$refreshResult){
          		$resultList['result'] = 0;
          	}else{
          		$resultList['result'] = 1;
          	}
        }

        $this->ajaxReturn($resultList);
	}

	/**
	 * 删除球会处理
	 * 返回值：
	 *     删除失败：0
	 *     删除成功：1
	 */
	public function deleteClubHandel(){
		//实例化球馆对象
		$club = M('club_table');
		//实例化用户对象
		$user = M('user_table');

		//从前台过去球馆id
		$clubId = $_POST['club_id'];
		//从session获取球馆主id
		$masterId = session('id');

		//删除球会
		$where['id'] = $clubId;
		$where['master_id'] = $masterId;
		$deleteResult = $club->where($where)->delete();

		if(!$deleteResult){
			$resultList['result'] = 0;
		}else{
			//判断会长特性
			unset($where);
			$where['master_id'] = $masterId;
			$clubCount = $club->where($where)->count();
			if($clubCount == 0){
				$accessType = session('access');
				unset($where);
				$where['id'] = session('id');
				if($accessType == 2){
					session('access', 0);
					$data['access'] = 0;
					$user->where($where)->save($data);
				}elseif($accessType == 4){
					session('access', 1);
					$data['access'] = 1;
					$user->where($where)->save($data);
				}elseif($accessType == 6){
					session('access', 3);
					$data['access'] = 3;
					$user->where($where)->save($data);
				}elseif($accessType == 7){
					session('access', 5);
					$data['access'] = 5;
					$user->where($where)->save($data);
				}
			}

			$resultList['result'] = 1;
		}

		$this->ajaxReturn($resultList);
	}
	
	public function clubDetail()
	{
		$club_id=$_POST['club_id'];
		$user_id=session('id');
		$club=M('club_table');
		$result=$club->where("id='%d'",$club_id)->find();
		$status=$club->where("id='%d'",$club_id)->getField('club_status');
		$resultList["result"]=$result;
		$this->ajaxReturn($resultList);
	}
	public function updateClub()
	{
		if (IS_POST) {
		  if (!session('id')) $this->error("请先登录");
		 
		  $upload = new \Org\Net\UploadFile();  
          $upload->maxSize = 3145728;  
          //设置文件上传类型  
          $upload->allowExts = array('jpg','gif','png','jpeg');  
          //设置文件上传位置  
          //$upload->savePath = __PUBLIC__."/Img/Uploads/";
          $upload->savePath = "./Public/Img/Uploads/clubImg/";  
          //设置文件上传名(按照时间)  
          $upload->saveRule = "time";  
          if (!$upload->upload()){ 
   
          }else{  
              //上传成功，获取上传信息  
              $info = $upload->getuploadFileInfo();
              $savename = $info[0]['savename'];
              $imgurl = "__PUBLIC__/Img/Uploads/clubImg/".$savename;
              $data['club_picture']=$imgurl;			  
          }
          
		$club=M('club_table');
		$club_id = $_POST["id"];
		if  ($_POST["name"]!=NULL)
		$data["name"] = $_POST["name"];
	 
	    if  ($_POST["introduction"]!=NULL)
	    $data["introduction"] = $_POST["introduction"];
	    
	    if  ($_POST["club_number_count"]!=NULL)
		$data["club_number_count"]=$_POST["club_number_count"];
	     if  ($_POST["club_kind"]!=NULL)
		$data["club_kind"]=$_POST["club_kind"]; 
         
			if ($club->where("id='%d'",$club_id)->save($data))
			{
				$this->success("修改成功");
			}
			
		} 
	}
	public function applyClubPeople()
	{
		$club_id=$_POST['club_id'];
		$apply=M('club_member_table');
		$people=$apply->join('thinkphp_user_table on thinkphp_club_member_table.member_id=thinkphp_user_table.id')->where("club_id='%d' and member_status='%d'",array($club_id,0))->field('name,id')->select();
		$resultList["result"]=$people;
		$this->ajaxReturn($resultList);
	}
	public function clubPeople()
	{
		$club_id=$_POST['club_id'];
		$apply=M('club_member_table');
		$people=$apply->join('thinkphp_user_table on thinkphp_club_member_table.member_id=thinkphp_user_table.id')->where("club_id='%d' and member_status='%d'",array($club_id,1))->field('name,id')->select();
		$resultList["result"]=$people;
		$this->ajaxReturn($resultList);
	}
	public function permit_join()
	{
		$club_id=$_POST['club_id'];
		$name=$_POST['name'];
		$apply=M('club_member_table');
		$user=M('user_table');
		$user_id=$user->where("name='%s'",$name)->getField('id');
		if ($user_id)
		{
		$data['member_status']=1;
		$people=$apply->where("club_id='%d' and member_id='%d'",array($club_id,$user_id))->save($data);
		$resultList["result"]=0;
		}
		else
		{
			$resultList["result"]=1;
		}
		$this->ajaxReturn($resultList);
	}
	
	public function kick_member()
	{
		
		$club_id=$_POST['club_id'];
		$name=$_POST['name'];
		$apply=M('club_member_table');
		$user=M('user_table');
		$club=M('club_table');
		$user_id=$user->where("name='%s'",$name)->getField('id');
		if ($user_id)
		{
		if ($club->where("id='%d' and master_id='%d'",array($club_id,$user_id))->find())
		{
			$resultList["result"]=2;
		}
		else
		{
		$
		$people=$apply->where("club_id='%d' and member_id='%d'",array($club_id,$user_id))->delete();
		$resultList["result"]=0;
		}
		}
		else
		{
			$resultList["result"]=1;
		}
		$this->ajaxReturn($resultList);
	}
}
